define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'banc/index' + location.search,
                    add_url: 'banc/add',
                    edit_url: 'banc/edit',
                    del_url: 'banc/del',
                    multi_url: 'banc/multi',
                    import_url: 'banc/import',
                    table: 'line_banc',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                showExport:false,//去掉导出
                // search:false,//去掉ID搜索
                // commonSearch:false,//去掉放大镜
                // showToggle:false,//去掉切换
                // showColumns:false,//去掉列
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'line_id', title: __('Line_id')},
                        {field: 'line.line_name', title: __('Line.line_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'depart_time', title: __('Depart_time'), formatter: Table.api.formatter.datetime, operate: 'LIKE'},
                        // {field: 'driver_id', title: __('Driver_id')},
                        {field: 'driver.driver_name', title: __('Driver.driver_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'banc_sn', title: __('Banc_sn'), operate: 'LIKE'},
                        {field: 'distance', title: __('Distance'), operate:'BETWEEN'},
                        {field: 'distance_time', title: __('Distance_time'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        // {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            $("#c-line_id").data("eSelect", function(one){
                console.log(one);
                Fast.api.ajax({
                    url:'banc/getStartStation',
                    data:{id:one.id}
                 }, function(data, ret){
                    console.log(ret.data);
                    $("#c-station_name_json").val(ret.data);
                    $("[data-name='row[station_name_json]'] ").trigger("fa.event.refreshfieldlist");
                    return false;
                 }, function(data, ret){
                    //失败的回调
                    alert(ret.msg);
                    return false;
                 });
            });
        },
        edit: function () {
            Controller.api.bindevent();
            $("#c-line_id").data("eSelect", function(one){
                console.log(one);
                Fast.api.ajax({
                    url:'banc/getStartStation',
                    data:{id:one.id}
                 }, function(data, ret){
                    console.log(ret.data);
                    $("#c-station_name_json").val(ret.data);
                    $("[data-name='row[station_name_json]'] ").trigger("fa.event.refreshfieldlist");
                    return false;
                 }, function(data, ret){
                    //失败的回调
                    alert(ret.msg);
                    return false;
                 });
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
